<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\admin\controller;

use app\admin\model\Subject;
use app\admin\model\Grade;
use think\Db;

class DashboardController extends CommonController {

    /**
     * 
     * 获取每天学生的登录和注册数
     */
    public function getData() {
        $rows = $_POST['rows'];
        $page = $_POST['page'];
        $param = $this->getDataByCampusid($_POST);
        $notice = Db::table('ew_login_live')
            ->where($param)
            ->order('login_date DESC')
            ->limit($rows * ($page - 1), $rows)
            ->select();
        $total = Db::table('ew_login_live')
            ->where($param)
            ->count();
        //加上数据
        //foreach ($notice as $k=>$v){
        //    $notice[$k]['login_all'] = $notice[$k]['login_all']+$notice[$k]['false'];
        //}
        $data['total'] = $total;
        $data['rows'] = $notice;
        return json_encode($data);
    }

    /*---------------以下的是》关于我们》----------------*/
    /**
     * 获取数据
     * @return string
     */
    public function getUsData() {
        $rows = $_POST['rows'];
        $page = $_POST['page'];
        $notice = Db::table('ew_us')
            ->limit($rows * ($page - 1), $rows)
            ->select();
        $total = 1;
        $data['total'] = $total;
        $data['rows'] = $notice;
        return json_encode($data);
    }
    /**
     *editInfo 修改数据-html
     * 状态
     */
    public function editInfo(){
        $data = Db::table('ew_us')->where('us_id',$_POST['id'])->find();
        $this->assign ('data',$data);
        return $this->fetch("us/edit");
    }

    /**
     *editInfo 修改
     */
    public function updateLife(){
        $data = array();
        //===上传图片========
        if(!empty($_FILES['thumb']['tmp_name'])){
            $imginfo = $this->uploadFile($_FILES['thumb']['tmp_name'],$_FILES['thumb']['name'],$_FILES['thumb']['size']);
            if($imginfo['status'] == 200){
                $data['us_logo'] = $imginfo['msg'];
            }else{
                return json_encode(['status'=>0,'msg'=>$imginfo['msg']]);
            }
        }
        //=====end===========
        $data['us_content'] = $_POST['con'];
        $data['us_date'] = date('Y-m-d H:i:s');
        $res = Db::table('ew_us')->where('us_id',$_POST['us_id'])
            ->update($data);
        if($res){
            return json_encode(['status'=>1,'msg'=>"成功！"]);
        }else{
            return json_encode(['status'=>0,'msg'=>"失败！"]);
        }
    }
}

